<template>
	<view class="special-content">
		<view class="special-list">
			<view class="special-item" v-for="(item,index) in exerciseList" :key="item.id"
				@click="gotoPractice(item.id)">
				<view class="spec-title">{{item.name}}</view>
				<view class="spec-num">
					<!-- <view>{{item.num}}题</view> -->
					<u-icon name="arrow-right" color="#666666" size="28"></u-icon>
				</view>
			</view>
			<uni-load-more :status="status" :icon-size="14" :content-text="contentText"></uni-load-more>

		</view>
	</view>
</template>

<script>
	import {
		getChapterlist
	} from '../../api/index.js'
	export default {
		data() {
			return {
				currentTag: 0,
				//
				subject: 1,
				ifBottomRefresh: false, //是否触底
				status: 'more',
				page: 1,


				contentText: {
					contentdown: '上拉加载更多~',
					contentrefresh: '加载中',
					contentnomore: '暂无更多~'
				},
				exerciseList: [] ,//列表数据
				lastPage:1

			}
		},
		mounted() {
			this.getChapterlists()
		},
		onLoad(options) {
			this.currentTag = options.currentTag
			if (options.currentTag == 4) {
				this.subject = 2
			}
		},
		onReachBottom() {
			if (this.status != 'noMore') {
				// console.log("触底")
				
				this.status = 'loading';
				this.ifBottomRefresh = true
				this.page++
				this.getChapterlists()

			} else {
				// console.log('123没有了')
				this.status = "noMore"
			}
		},

		methods: {
			// 跳转到练习
			gotoPractice(id) {
				let that = this
				if (uni.getStorageSync('access_token') != '') {
					uni.navigateTo({
						url: '/pagesA/topicPractice/index?type=3&currentTag=' + this.currentTag + '&id=' + id
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '您当前未登录，是否登录？',
						success: function(res) {
							if (res.confirm) {
								that.gotoLigin()
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			// list
			getChapterlists() {
				let that = this;
				getChapterlist({
					subject: this.subject,
					page: this.page,
				}).then(res => {
					this.exerciseList=that.exerciseList.concat(res.data.list)
					this.lastPage = res.data.last_page
					if(this.page>=this.lastPage){
						this.status = "noMore"
						return
					}
				}).catch()
			}
		}
	}
</script>

<style lang="scss">
	.special-list {
		// padding: 20rpx;
		width: 95%;
		margin: 20rpx auto;
		background-color: #fff;

		.special-item {
			display: flex;
			justify-content: space-between;
			padding: 35rpx 0;
			width: 95%;
			margin: 0 auto;
			font-size: 28rpx;
			border-bottom: 1rpx solid #DFE0E6;

			.spec-title {
				color: #313233;
			}

			.spec-num {
				display: flex;
				align-items: center;
				color: #999999;
			}
		}
	}
</style>